<?php
/*
    Copyright (C) 2008 - 2010 Inanta Martsanto
    
    This file is part of Koma.

    Koma is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Koma is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Koma.  If not, see <http://www.gnu.org/licenses/>.
    
    Inanta Martsanto (inanta@inationsoft.com)
*/

include_once(KOMA_SMARTY_PATH.'/Smarty.class.php');

final class KomaTemplate extends KomaSingletonObject
{       
        function __construct()
        {
                $this->createProperties(array('File' => '', 'Engine' => new Smarty()));
                $this->setReadOnlyProperties('Engine');
                
                $this->Engine->template_dir = KOMA_THEME_PATH;
                $this->Engine->cache_dir = KOMA_CACHE_PATH;
                $this->Engine->compile_dir = KOMA_COMPILE_PATH;
                
                $this->Engine->assign(array(
                                    'koma_url' => KOMA_URL, 
                                    'koma_root_path' => KOMA_ROOT_PATH, 
                                    'langcode' => defined('KOMA_LOCALE') ? KOMA_LOCALE : KOMA_DEFAULT_LOCALE, 
                                    'charset' => defined('KOMA_CHARSET') ? KOMA_CHARSET : KOMA_DEFAULT_CHARSET));
        }
        
        function display($resource_name, $cache_id = null, $compile_id = null)
        {
                $this->Engine->display($resource_name, $cache_id, $compile_id);
        }
        
        function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
        {
                return $this->Engine->fetch($resource_name, $cache_id, $compile_id, $display);
        }
        
        function assign($tpl_var, $value = null)
        {
                $this->Engine->assign($tpl_var, $value);
        }
        
        function append($tpl_var, $value=null, $merge=false)
        {
                $this->Engine->append($tpl_var, $value, $merge);
        }
        
        function clear_assign($tpl_var)
        {
                $this->Engine->clear_assign($tpl_var);
        }
        
        function clear_all_assign()
        {
                $this->Engine->clear_all_assign();
        }
        
	static function getInstance()
	{
		return self::createInstance(__CLASS__);
	}
}
?>